<template>
  <div>
    <header>
      <n-bar></n-bar>
    </header>
    <van-address-edit
      :area-list="areaList"
      show-postal
      show-set-default
      :address-info="info"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
    >
      <template #default>
        <div>
          <van-radio-group v-model="radio" direction="horizontal">
            <p class="bq">标签</p>
            <van-radio name="家" checked-color="#ff7d04">家</van-radio>
            <van-radio name="公司" checked-color="#ff7d04">公司</van-radio>
            <van-radio name="学校" checked-color="#ff7d04">学校</van-radio>
          </van-radio-group>
        </div>
      </template>
    </van-address-edit>
    <van-button class="btn1" size="small" type="warning" @click="del">
      删除
    </van-button>
  </div>
</template>

<script>
import { areaList } from "@vant/area-data";
import { addressadd, addressedit, addressremove } from "../requset/app";
export default {
  data() {
    return {
      radio: this.$route.query.id ? this.$route.query.radio : "家",
      info: {
        ...this.$route.query,
        isDefault: this.$route.query.isDefault == "true" ? true : false,
      },
      areaList: areaList,
    };
  },
  methods: {
    del() {
      addressremove({
        id: this.$route.query.id,
      }).then((res) => {
        console.log(res);
        this.$router.push("/address");
      });
    },
    onSave(e) {
      // console.log(e, "表单内容");
      if (this.$route.query.id) {
        addressedit({
          id: this.$route.query.id,
          uid: this.$store.getters.getUserInfo.uid,
          username: e.name,
          userphone: e.tel,
          regioncode: e.areaCode,
          location: e.province + e.city + e.county,
          useraddress: e.addressDetail,
          status: e.isDefault ? 1 : 0,
          lable: this.radio,
        }).then((res) => {
          console.log(res, "地址编辑");
          if (res.code == 200) {
            this.$router.push("/address");
          }
        });
      } else {
        addressadd({
          uid: this.$store.getters.getUserInfo.uid,
          username: e.name,
          userphone: e.tel,
          regioncode: e.areaCode,
          location: e.province + e.city + e.county,
          useraddress: e.addressDetail,
          status: e.isDefault ? 1 : 0,
          lable: this.radio,
        }).then((res) => {
          console.log(res, "地址添加");
          if (res.code == 200) {
            this.$router.push("/address");
          }
        });
      }
    },
  },
};
</script>

<style scoped>
.btn1 {
  width: 340px;
  height: 45px;
  border-radius: 50px;
  margin-left: 20px;
}
.bq {
  margin: 15px;
}
/* 头部 */
header {
  background-color: #ff6040;
  box-sizing: border-box;
}

/* 顶部信息 */
header .top_box {
  height: 0.44rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.06rem 0 0.17rem;
  box-sizing: border-box;
}

header .top_box > a span {
  font-size: 0.17rem;
  color: #ffffff;
}

header .top_box h2 {
  opacity: 0.8;
  font-size: 0.17rem;
  color: #ffffff;
  margin-left: 0.23rem;
}

header .top_box .more {
  width: 0.87rem;
  height: 0.32rem;
  background: rgba(255, 119, 51, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 0.405rem;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
}

header .top_box .more .line {
  width: 1px;
  height: 0.19rem;
  background: rgba(255, 255, 255, 0.25);
}

header .top_box .more a span {
  font-size: 0.19rem;
  opacity: 0.8;
  color: #ffffff;
}

.address > div {
  /* background-color: orangered; */
  line-height: 0.5rem;
  border-bottom: 1px solid #ccc;
  margin-left: 0.1rem;
  font-size: 0.15rem;
}
.address > div input {
  width: 75%;
  margin-left: 0.1rem;
  border: none;
  outline: none;
  margin-top: 0.02rem;
}
.address .name > input {
  /* background-color: red; */
  margin-left: 0.22rem;
}
</style>
